package com.wengyingjian.https;


import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by hzwengyingjian on 17/1/23.
 */
public class Tb {

    public static void main(String[] args) throws IOException {
        String url = "https://login.taobao.com/aso/tgs?domain=alimama&sign_account=78ddbd8eafb74d4573fbbac5677bfa45&service=user_on_taobao&target=687474703A2F2F7777772E616C696D616D612E636F6D2F696E6465782E68746D";
        OkHttpClient client = new OkHttpClient();
        Request.Builder b = new Request.Builder().url(url);
        Map<String, String> map = getCookie();
        for (Map.Entry<String, String> e : map.entrySet()) {
            b.addHeader(e.getKey(), e.getValue());
        }
        Request request = b.build();
        Response response = client.newCall(request).execute();
        System.out.println("respBody=" + response.body().string());
        String location1 = response.header("location");
        System.out.println("location1=" + location1);

    }

    public static Map getCookie() {
        String headerStr = "accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\n"
                + "accept-encoding:gzip, deflate, sdch, br\n" + "accept-language:zh-CN,zh;q=0.8,en;q=0.6\n"
                + "cookie:thw=cn; cna=vT8DEV9fBn0CAXJxxYPndJaI; munb=1126400639; v=0; linezing_session=z4oi78cBjzYlXcih2lbkI6gM_1485009030955Vjq9_1; uc2=wuf=https%3A%2F%2Ftrade.tmall.com%2Fdetail%2ForderDetail.htm%3Fbiz_order_id%3D3005257425353906%26forward_action%3D; _tb_token_=f33ba340134e3; _umdata=0823A424438F76AB09665CC0588377B5D3600910B699A14574A872ACA37D32E614C496F24F449463CD43AD3E795C914CFACB4FA34E3AAA55D18DBBC69DF31883; uc1=cookie14=UoW%2FWNO0KBPBNA%3D%3D&lng=zh_CN&cookie16=Vq8l%2BKCLySLZMFWHxqs8fwqnEw%3D%3D&existShop=true&cookie21=W5iHLLyFfXVRCJf5lG0u7A%3D%3D&tag=7&cookie15=W5iHLLyFOGW7aA%3D%3D&pas=0; uc3=sg2=BxpRSReStIeCmWep1j1R677YRtWK6FNc0SWEmUKfmG4%3D&nk2=EqefhWnclW8Zvw%3D%3D&id2=UoCLEaUbCeipTw%3D%3D&vt3=F8dARHXUUduaFBWDr2k%3D&lg2=WqG3DMC9VAQiUQ%3D%3D; existShop=MTQ4NTE1NzUxOQ%3D%3D; lid=q291611265; lgc=q291611265; tracknick=q291611265; cookie2=14e70455c63599a6db231ca5c959931f; sg=595; mt=np=&ci=0_1; cookie1=VAn%2BSrhUnehPiB3itMA4s%2FOhFo62QHTUdtDDiK%2BaJB4%3D; unb=1126400639; skt=6e191d5c7c944fe2; t=e7e53a3daff516f5c20baebac84ec5a8; _cc_=W5iHLLyFfA%3D%3D; tg=0; _l_g_=Ug%3D%3D; _nk_=q291611265; cookie17=UoCLEaUbCeipTw%3D%3D; lc=Vy%2BdFYBitfWv3QlFnMe3; l=AgYG-kTRNK0CZOorwQb6nIDz1vaIZ0oh; isg=AsDAv6jOjAZCjXACYVwg0hmpkUjzzKQTgnMZjjpRjFtutWDf4ll0o5aFu6qP\n"
                + "upgrade-insecure-requests:1\n"
                + "user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36";
        String[] lines = headerStr.split("\n");
        Map<String, String> headers = new HashMap<String, String>();
        headers.put(":authority", "login.taobao.com");
        headers.put(":method", "GET");
        headers.put(":path",
                "/aso/tgs?domain=alimama&sign_account=78ddbd8eafb74d4573fbbac5677bfa45&service=user_on_taobao&target=687474703A2F2F7777772E616C696D616D612E636F6D2F696E6465782E68746D");
        headers.put(":scheme", "https");

        for (String line : lines) {
            int index = line.indexOf(":");
            headers.put(line.substring(0, index), line.substring(index + 1, line.length()));
        }
        System.out.println("map=" + headers);
        return headers;
    }
}
